#include "rpc_manager.h"
#include <iostream>

namespace monitor
{
    GrpcManagerServiceImpl::GrpcManagerServiceImpl() {}

    GrpcManagerServiceImpl::~GrpcManagerServiceImpl() {}

    // 传入监控信息，不需要响应
    ::grpc::Status GrpcManagerServiceImpl::SetMonitorInfo(
        ::grpc::ServerContext *context,
        const ::monitor::proto::MonitorInfo *request,
        ::google::protobuf::Empty *response)
    {
        std::lock_guard<std::mutex> lock(map_mutex_);
        std::string name=request->name();
        monitor_map_[name].Clear();
        monitor_map_[name]=*request;
        
        // std::cout << "jinru" << request->soft_irq_size() << std::endl;

        return grpc::Status::OK;
    }

    // 调用GetMonitorInfo获取监控信息，不需要请求
    ::grpc::Status GrpcManagerServiceImpl::GetMonitorInfo(
        ::grpc::ServerContext *context, const ::monitor::proto::GetRequest *request,
        ::monitor::proto::MonitorInfo *response)
    {
        std::lock_guard<std::mutex> lock(map_mutex_);
        std::string name=request->sign();
        *response = monitor_map_[name];
        return grpc::Status::OK;
    }

} // namespace monitor
